using System;
using System.Collections.ObjectModel;
using RideMe.AddIns.Interfaces;

namespace RideMe.AddIns
{
    /// <summary>
    /// This class provides access to easy-to-use methods for working with add-ins
    /// </summary>
    public class AddInService
    {
        #region Static Properties

        /// <summary>
        /// This grabs all loaded add-ins, loading them first if not already done so
        /// </summary>
        public static Collection<IAddIn> LoadedAddIns
        {
            get
            {
                if (_loadedAddIns == null)
                    _loadedAddIns = Discovery.FindAddIns();
                return _loadedAddIns;
            }
            set { _loadedAddIns = value; }
        }

        #endregion

        #region Static Variables

        private static Collection<IAddIn> _loadedAddIns = null;

        #endregion

        #region Static Methods

        /// <summary>
        /// This initializes the AddInService, first discovering all add-ins, and then initializing them all
        /// </summary>
        public static void Init()
        {
            foreach (IAddIn addin in LoadedAddIns)
                addin.Init(RideMe.AddIns.Base.ApplicationContext.Current);
        }
   
        #endregion
    }
}
